package com.javase.实验八_异常;

public class Person {
    private String name;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age){
        try{
            if(age<=0)
                throw new MyException("年龄不合法");
            else
                this.age = age;
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Person person = new Person();
        person.setAge(0);
    }
}
